class Solution(object):
    def minAddToMakeValid(self, s):
        count = 0
        t = 0
        for c in s:
            if c == '(':
                count += 1
            else:
                count -= 1
                if count < 0:
                    count = 0
                    t += 1
        return t + count


data = Solution()
s = ")))("
print(data.minAddToMakeValid(s))
